﻿Imports System.Text
Namespace DataMaster
    Public Class clsMSTDISCOUNT
        Inherits ADODBU.Recordset

        Private mFieldList As New ArrayList
        Private mStrFieldList As String
        Private mStrSql As String
        Public Sub New()
            mFieldList.Add("MSTDISCOUNT.DISACRCOD")
            mFieldList.Add("MSTDISCOUNT.DISCACREXT")
            mFieldList.Add("MSTDISCOUNT.DISCACRDESC")
            mFieldList.Add("MSTDISCOUNT.DISCACRTYPE")
            mFieldList.Add("MSTDISCOUNT.DISCACRGRP")
            mFieldList.Add("MSTDISCOUNT.DISCACRMRG")
            mFieldList.Add("MSTDISCOUNT.DISCACRPERCEN")
            mFieldList.Add("MSTDISCOUNT.DISCACRAMOUNT")
            mFieldList.Add("MSTDISCOUNT.DISCACRDCRE")
            mFieldList.Add("MSTDISCOUNT.DISACRDMAJ")
            mFieldList.Add("MSTDISCOUNT.DISACRUTIL")
            mFieldList.Add("MSTDISCOUNT.DISACRPROG")
            mStrSql = "Select DISACRCOD,DISCACREXT,DISCACRDESC,DISCACRTYPE,DISCACRGRP,DISCACRMRG,DISCACRPERCEN,DISCACRAMOUNT,DISCACRDCRE,DISACRDMAJ,DISACRUTIL,DISACRPROG from MSTDISCOUNT  "
        End Sub

        Public Overloads Sub Open(cCriteria As String)
            Dim cSql As String
            cSql = mStrSql & cCriteria
            MyBase.AddPK("DISCACREXT")
            MyBase.IsCanUpdate = True
            Try
                MyBase.Open(cSql, "MSTDISCOUNT", Me.DbConn)
            Catch e As Exception
                Me.ErrMessage = e.Message
            End Try
        End Sub


        Public Function GetRowList(dbConn As ADODBU.dbConn, cCriteria As String) As ADODBU.RowClassList(Of clsMSTDISCOUNTRow)
            Dim cmd As System.Data.IDbCommand = dbConn.DBAFactory.GetCommand
            cmd.CommandText = Me.mStrSql & cCriteria
            cmd.CommandType = CommandType.Text
            cmd.Connection = dbConn.Connection
            Return GetDataFromReader(cmd.ExecuteReader)
        End Function

        Public Function GetRowList() As ADODBU.RowClassList(Of clsMSTDISCOUNTRow)
            Return Me.GetDataFromReader(Me.DataTable.CreateDataReader)
        End Function
        Private Function GetDataFromReader(ByVal rdr As IDataReader) As ADODBU.RowClassList(Of clsMSTDISCOUNTRow)
            Dim colData As New ADODBU.RowClassList(Of clsMSTDISCOUNTRow)
            Dim xData As clsMSTDISCOUNTRow
            Dim buffer() As Byte
            Dim len As Long
            Dim mStr As New System.IO.MemoryStream

            Do While rdr.Read
                xData = New clsMSTDISCOUNTRow()
                If Not rdr.IsDBNull(0) Then
                    xData.DISACRCOD = rdr.GetInt32(0)
                End If
                If Not rdr.IsDBNull(1) Then
                    xData.DISCACREXT = rdr.GetString(1)
                End If
                If Not rdr.IsDBNull(2) Then
                    xData.DISCACRDESC = rdr.GetString(2)
                End If
                If Not rdr.IsDBNull(3) Then
                    xData.DISCACRTYPE = rdr.GetInt32(3)
                End If
                If Not rdr.IsDBNull(4) Then
                    xData.DISCACRGRP = rdr.GetInt32(4)
                End If
                If Not rdr.IsDBNull(5) Then
                    xData.DISCACRMRG = rdr.GetDecimal(5)
                End If
                If Not rdr.IsDBNull(6) Then
                    xData.DISCACRPERCEN = rdr.GetDecimal(6)
                End If
                If Not rdr.IsDBNull(7) Then
                    xData.DISCACRAMOUNT = rdr.GetDecimal(7)
                End If
                If Not rdr.IsDBNull(8) Then
                    xData.DISCACRDCRE = rdr.GetDateTime(8)
                End If
                If Not rdr.IsDBNull(9) Then
                    xData.DISACRDMAJ = rdr.GetDateTime(9)
                End If
                If Not rdr.IsDBNull(10) Then
                    xData.DISACRUTIL = rdr.GetString(10)
                End If
                If Not rdr.IsDBNull(11) Then
                    xData.DISACRPROG = rdr.GetString(11)
                End If
                colData.Add(xData)
            Loop
            rdr.Close()
            rdr.Dispose()
            Return colData
        End Function
        Public Function GetReader(ByVal dbConn As ADODBU.dbConn, ByVal cCriteria As String) As IDataReader
            Dim cmd As System.Data.IDbCommand = dbConn.DBAFactory.GetCommand
            cmd.CommandText = Me.mStrSql & cCriteria
            cmd.CommandType = CommandType.Text
            cmd.Connection = dbConn.Connection
            Return cmd.ExecuteReader
        End Function
        Public Function GetClassRow() As clsMSTDISCOUNTRow
            Dim crData As New clsMSTDISCOUNTRow
            crData = GetClassRow(Me.GetCurrentDataRow)
            Return crData
        End Function


        Public Function GetClassRow(recdata As ADODBU.Recordset) As clsMSTDISCOUNTRow
            Dim crData As clsMSTDISCOUNTRow
            crData = New clsMSTDISCOUNTRow(recdata.GetCurrentDataRow)
            Return crData
        End Function


        Public Function GetClassRow(recdata As DataRow) As clsMSTDISCOUNTRow
            Return New clsMSTDISCOUNTRow(recdata)
        End Function


        Public Function SaveClassRow(crData As clsMSTDISCOUNTRow, lAddnew As Boolean, Optional lTransaction As Boolean = False) As Boolean
            Dim lSavedata As Boolean
            If lAddnew Then
                MyBase.AddNew()
            End If
            crData.DataSource = Me
            crData.SaveToDataSource()
            lSavedata = True
            Try
                MyBase.Update(lTransaction)
                If MyBase.ErrMessage.Length <> 0 Then
                    lSavedata = False
                End If
            Catch e As Exception
                lSavedata = False
            End Try
            Return lSavedata
        End Function


    End Class
End Namespace